﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB.YJKControls;

namespace HYLightingEquipmentLay.Forms
{
	public partial class FormIndoorAutomaticLayout : HYBaseForm
	{
		public int SelectionMethod
		{
			get
			{
				return this.selectionMethod;
			}
			set
			{
				this.selectionMethod = value;
			}
		}

		public FormIndoorAutomaticLayout(Autodesk.Revit.DB.Document doc)
		{
			this.InitializeComponent();
			this.doc = doc;
		}

		private void btnSet_Click(object sender, EventArgs e)
		{
			new FormIndoorAutomaticLayoutSetting(new System.Drawing.Point(base.Location.X, base.Location.Y + 123), this.doc).ShowDialog();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.OK;
			base.Close();
		}

		private void btnCal_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void rdbFrameSelectedArea_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdbFrameSelectedArea.Checked)
			{
				this.SelectionMethod = 1;
				return;
			}
			this.SelectionMethod = 0;
		}

		private void FormIndoorAutomaticLayout_Load(object sender, EventArgs e)
		{
			this.GetIndoorAutomaticLayoutInfo();
		}

		private void GetIndoorAutomaticLayoutInfo()
		{
			if (this.userSetting.GetIndoorAutomaticLayoutText()[0] == "1")
			{
				this.rdbFrameSelectedArea.Checked = true;
			}
			else
			{
				this.rdbActiveView.Checked = true;
			}
			string[] indoorAutomaticLayoutSettingText = this.userSetting.GetIndoorAutomaticLayoutSettingText();
			if (indoorAutomaticLayoutSettingText[0] != "")
			{
				FormIndoorAutomaticLayoutSetting.SwitchMerging = indoorAutomaticLayoutSettingText[0].ToDouble(0.0);
				return;
			}
			FormIndoorAutomaticLayoutSetting.SwitchMerging = 500.0;
		}

		private void FormIndoorAutomaticLayout_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.SetIndoorAutomaticLayoutInfo();
		}

		private void SetIndoorAutomaticLayoutInfo()
		{
			string[] texts = new string[]
			{
				this.SelectionMethod.ToString()
			};
			this.userSetting.WriteIndoorAutomaticLayoutText(texts);
		}

		private Document doc;

		private int selectionMethod;

		private HVACUserSetting userSetting = new HVACUserSetting();
	}
}
